package ui;
import Pojo.Reader;
import Service.ReaderService;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ReaderCheckManger extends JDialog implements ActionListener {
    private Reader reader;
    private ReaderManager readerManager;
    private JPanel contentPanel = new JPanel();
    private JTextField txtName;
    private JTextField txtAge;
    private JTextField txtSub;
    private JTextField txtSex;
    private ReaderService readerService = new ReaderService();

    public ReaderCheckManger(Reader reader, ReaderManager readerManager) {
        this.reader = reader;
        this.readerManager = readerManager;
        setTitle("读者信息编辑");
        setBounds(100, 100, 570, 474);
        getContentPane().setLayout(new BorderLayout());
        contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
        getContentPane().add(contentPanel, BorderLayout.CENTER);
        contentPanel.setLayout(null);
//姓名
        JLabel labelName = new JLabel("姓名");
        labelName.setBounds(160, 40, 60, 15);
        contentPanel.add(labelName);
        txtName = new JTextField();
        txtName.setBounds(230, 39, 170, 28);
        txtName.setColumns(10);
        contentPanel.add(txtName);
//性别
        JLabel labelSex = new JLabel("性别");
        labelSex.setBounds(160, 90, 60, 15);
        contentPanel.add(labelSex);
        txtSex = new JTextField();
        txtSex.setBounds(230, 85, 170, 28);
        txtSex.setColumns(10);
        contentPanel.add(txtSex);
//年龄
        JLabel labelAge = new JLabel("年龄");
        labelAge.setBounds(160, 140, 60, 15);
        contentPanel.add(labelAge);
        txtAge = new JTextField();
        txtAge.setBounds(230, 140, 170, 28);
        txtAge.setColumns(10);
        contentPanel.add(txtAge);
//专业
        JLabel labelSub = new JLabel("学院");
        labelSub.setBounds(160, 190, 60, 15);
        contentPanel.add(labelSub);
        txtSub = new JTextField();
        txtSub.setBounds(230, 190, 170, 28);
        txtSub.setColumns(10);
        contentPanel.add(txtSub);
        JButton btnCanel = new JButton("取消");
        btnCanel.setBounds(305, 240, 165, 35);
        btnCanel.addActionListener(this);
        contentPanel.add(btnCanel);
        this.setModal(true);
        txtName.setText(reader.getName());
        txtSex.setText(reader.getSex());
        txtAge.setText(reader.getAge());
        txtSub.setText(reader.getSub());

        txtName.setEditable(false);
        txtSex.setEditable(false);
        txtAge.setEditable(false);
        txtSub.setEditable(false);
        this.setVisible(true);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals("取消")) {
            this.dispose();
        }
    }
}
